﻿namespace MicroCloud.Dependency
{
    /// <summary>
    /// 基于Scoped生命周期的数据字典，可用于在Scoped环境中传递数据
    /// </summary>
    public sealed class ScopedDictionary : ConcurrentDictionary<string, object>, IDisposable
    {
        #region 属性
        /// <summary>
        /// 获取或设置 当前执行的功能
        /// </summary>
        public IFunction Function { get; set; }
        
        /// <summary>
        /// 获取或设置 对于当前功能有效的角色集合，用于数据权限判断
        /// </summary>
        public OnlineRole[] DataAuthValidRoles { get; set; } = Array.Empty<OnlineRole>();
        
        /// <summary>
        /// 获取或设置 当前操作审计
        /// </summary>
        public AuditOperationEntry AuditOperation { get; set; }
        
        /// <summary>
        /// 获取或设置 当前用户
        /// </summary>
        public ClaimsIdentity Identity { get; set; }

        /// <summary>
        /// 获取或设置 事务隔离级别
        /// </summary>
        public IsolationLevel? IsolationLevel { get; set; }

        #endregion

        #region 释放资源
        /// <summary>
        /// 释放资源
        /// </summary>
        public void Dispose()
        {
            Function = null;
            AuditOperation = null;
            Identity = null;
            IsolationLevel = null;
            this.Clear();
        }

        #endregion

    }

}
